package com.xgb.springcloudserver.controller;

import com.netflix.discovery.converters.Auto;
import com.xgb.springcloudserver.common.AjaxResult;
import com.xgb.springcloudserver.domain.UserInfo;
import com.xgb.springcloudserver.service.UserInfoService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description:
 * @author: chenzuolin
 * @time: 2021/3/8 21:51
 */
@RestController
@RequestMapping("/provider")
public class HiController {

    @Autowired
    UserInfoService userInfoService;

    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/msg")
    public AjaxResult hi() {
        String msg = "hi, 我是服务提供者：server-client，我的端口是" + serverPort;
        return AjaxResult.success(msg);
    }

    @GetMapping("/findById/{id}")
    public AjaxResult findUserInfoById(@PathVariable("id") String id) {
        System.out.println("================" + id);
        UserInfo userinfo = userInfoService.findUserInfoById(id);
        return AjaxResult.success(userinfo);
    }

    @GetMapping("/findAll")
    public AjaxResult findAllUserInfo() {
        List<UserInfo> allUserInfo = userInfoService.findAllUserInfo();
        return AjaxResult.success(allUserInfo);
    }
}
